#include "connectionmanager.h"

ConnectionManager::ConnectionManager()
{
}

bool ConnectionManager::sync(QString path1, QString path2)
{
    _list.append(new Connection(path1, path2));

    return true;
}

void ConnectionManager::unsync(int id)
{
    _list.removeAt(id);
}

Connection* ConnectionManager::at(int id)
{
    return _list.at(id);
}

QString ConnectionManager::hasupdates()
{
    for(int i = 0; i < _list.count(); i++)
    {
        if(_list.at(i)->hasUpdates()) return "";
    }

    return false;
}

bool ConnectionManager::update()
{
    for(int i = 0; i < _list.count(); i++)
    {
        if(!_list.at(i)->update()) return false;
    }

    return true;
}

void ConnectionManager::run()
{
    int time_to_sleep = 1; //in minutes

    forever
    {
        if(this->hasupdates() == "")
        {
            this->update();
        }

        msleep(time_to_sleep*60*1000);
    }
}
